#include<bits/stdc++.h>
using namespace std;
inline long long read(){
    char ch=getchar();
    long long x=0,k=1;
    while(ch<'0'||ch>'9'){
        if(ch=='-') k=-1;
        ch=getchar();}
    while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*k;}
const int maxn=100005;
long long d[maxn],v[maxn],a[maxn],de[maxn];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    long long T;
    T=read();
    while(T--){
        long long n,m,l,vl,maxdis=-1,mindis=INT_MAX,flag1=0,flag2=0,tot=0,maxde=0;
        n=read(),m=read(),l=read(),vl=read();
        for(long long i=1;i<=n;i++) d[i]=read(),v[i]=read(),a[i]=read();
        for(long long i=1;i<=m;i++) de[i]=read();
        maxde=de[m];
        for(long long i=1;i<=n;i++) if(v[i]>vl&&d[i]<=maxde) tot++,maxdis=(maxdis,d[i]),mindis=min(mindis,d[i]);
        for(long long i=1;i<=m;i++){
            if(de[i-1]<mindis<de[i]) flag1=i;
            if(d[i]<maxdis<d[i+1]) flag2=i;}
        cout<<tot<<" "<<m-(flag2-flag1+1)<<'\n';}//no time left
    return 0;}
//Sally
